home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent2 / clib37x.lha / CLib37x / source / lib_source / compiler.h next >
C/C++ Source or Header  |  1998-03-18  |  5KB  |  206 lines

  1. /*
  2. **      $VER: compiler.h 37.31 (18.3.98)
  3. **
  4. **      Compiler independent register (and SAS/C extensions) handling
  5. **
  6. **      (C) Copyright 1997-98 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #ifndef COMPILER_H
  11. #define COMPILER_H
  12.  
  13.  /* ============================================================
  14.     There have been problems how to define the seglist pointer
  15.     under AROS, AmigaOS or elsewhere in a unique (and still
  16.     working!) way. It seems to make sense to use a new, global
  17.     type definition for it. This is done here. */
  18.  
  19. #ifndef _AROS
  20. # ifdef VBCC
  21. #  define SEGLISTPTR APTR
  22. # else /* !VBCC */
  23. #  include <dos/dos.h>
  24. #  define SEGLISTPTR BPTR
  25. # endif /* VBCC */
  26. #else /* !_AROS */
  27.   typedef struct SegList * SEGLISTPTR;
  28. #endif /* _AROS */
  29.  
  30.  /* ============================================================ */
  31.  
  32. /* Basically, Amiga C compilers must try to reach the goal to be
  33.    as SAS/C compatible as possible. But on the other hand,
  34.    when porting AmigaOS to other platforms, one perhaps
  35.    can't expect GCC becoming fully SAS/C compatible...
  36.  
  37.    There are two ways to make your sources portable:
  38.  
  39.     - using non ANSI SAS/C statements and making these
  40.       "available" to the other compilers (re- or undefining)
  41.     - using replacements for SAS/C statements and smartly
  42.       redefining these for any compiler
  43.  
  44.    The last mentioned is the most elegant, but may require to
  45.    rewrite your source codes, so this compiler include file
  46.    basically does offer both.
  47.  
  48.    For some compilers, this may have been done fromout project or
  49.    makefiles for the first method (e.g. StormC) to ensure compileablity.
  50.  
  51.    Basically, you should include this header file BEFORE any other stuff.
  52. */
  53.  
  54. /* ********************************************************************* */
  55. /* Method 1: redefining SAS/C keywords                                   */
  56. /*                                                                       */
  57. /* Sorry, this method does not work with register definitions for the current
  58. gcc version (V2.7.2.1), as it expects register attributes after the parameter
  59. description. (This is announced to be fixed with gcc V2.8.0).
  60. Moreover the __asm keyword has another meaning with GCC.
  61. Therefore ASM must be used. */
  62.  
  63. #ifdef __MAXON__  // ignore this switches of SAS/Storm
  64. #define __aligned
  65. #define __asm
  66. #define __regargs
  67. #define __saveds
  68. #define __stdargs
  69. #endif
  70.  
  71. #ifdef __GNUC__  // ignore this switches of SAS/Storm
  72. #define __d0
  73. #define __d1
  74. #define __d2
  75. #define __d3
  76. #define __d4
  77. #define __d5
  78. #define __d6
  79. #define __d7
  80. #define __a0
  81. #define __a1
  82. #define __a2
  83. #define __a3
  84. #define __a4
  85. #define __a5
  86. #define __a6
  87. #define __a7
  88. #endif
  89.  
  90. #ifdef VBCC
  91. #define __d0 __reg("d0")
  92. #define __d1 __reg("d1")
  93. #define __d2 __reg("d2")
  94. #define __d3 __reg("d3")
  95. #define __d4 __reg("d4")
  96. #define __d5 __reg("d5")
  97. #define __d6 __reg("d6")
  98. #define __d7 __reg("d7")
  99. #define __a0 __reg("a0")
  100. #define __a1 __reg("a1")
  101. #define __a2 __reg("a2")
  102. #define __a3 __reg("a3")
  103. #define __a4 __reg("a4")
  104. #define __a5 __reg("a5")
  105. #define __a6 __reg("a6")
  106. #define __a7 __reg("a7")
  107. #endif
  108.  
  109.  /* for SAS/C we don't need this, for StormC this is done in the
  110.     makefile or projectfile */
  111.  
  112. /*                                                                       */
  113. /* ********************************************************************* */
  114.  
  115.  
  116. /* ********************************************************************* */
  117. /* Method 2: defining our own keywords                                   */
  118. /*                                                                       */
  119. #ifdef __SASC
  120.  
  121. #  define REG(r)     register __ ## r
  122. #  define GNUCREG(r)
  123. #  define SAVEDS     __saveds
  124. #  define ASM        __asm
  125. #  define REGARGS    __regargs
  126. #  define STDARGS    __stdargs
  127. #  define ALIGNED    __aligned
  128.  
  129. #else
  130. # ifdef __MAXON__
  131.  
  132. #  define REG(r)    register __ ## r
  133. #  define GNUCREG(r)
  134. #  define SAVEDS
  135. #  define ASM
  136. #  define REGARGS
  137. #  define STDARGS
  138. #  define ALIGNED
  139.  
  140. # else
  141. #  ifdef __STORM__
  142.  
  143. #   define REG(r)  register __ ## r
  144. #   define GNUCREG(r)
  145. #   define SAVEDS  __saveds
  146. #   define ASM
  147. #   define REGARGS
  148. #   define STDARGS
  149. #   define ALIGNED
  150.  
  151. #  else
  152. #   ifdef __GNUC__
  153.  
  154. #    define REG(r)
  155. #    define GNUCREG(r)  __asm( #r )
  156. #    define SAVEDS  __saveds
  157. #    define ASM
  158. #    define REGARGS __regargs
  159. #    define STDARGS __stdargs
  160. #    define ALIGNED __aligned
  161.  
  162. #   else
  163. #    ifdef VBCC
  164. /* VBCC ignore this switch */
  165. #     define __aligned
  166. #     define __asm
  167. #     define __regargs
  168. #     define __saveds
  169. #     define __stdargs
  170. #     define __register
  171. #     define GNUCREG(r)
  172. #     define REG(r)
  173. #     define SAVEDS
  174. #     define ASM
  175. #     define REGARGS
  176. #     define STDARGS
  177. #     define ALIGNED
  178.  
  179. #    else
  180. #     ifdef _DCC
  181. #      define __aligned
  182. #      define __stdargs
  183. #      define GNUCREG(r)
  184. #      define ASM
  185.  
  186. #     else  /* any other compiler, to be added here */
  187.  
  188. #      define REG(r)
  189. #      define GNUCREG(r)
  190. #      define SAVEDS
  191. #      define ASM
  192. #      define REGARGS
  193. #      define STDARGS
  194. #      define ALIGNED
  195.  
  196. #     endif /*   _DCC      */
  197. #    endif /*   VBCC      */
  198. #   endif /*  __GNUC__   */
  199. #  endif /*  __STORM__  */
  200. # endif /*  __MAXON__  */
  201. #endif /*  __SASC     */
  202. /*                                                                       */
  203. /* ********************************************************************* */
  204.  
  205. #endif /* COMPILER_H */
  206.